using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using Microsoft.VisualBasic.CompilerServices;
namespace ePlanSysOman
{
  public partial class frmCardHarness
  {
    
    // Public FORMCLOSEEX2 As Boolean = True
    public string PLANNUM = "";
    private void  // ERROR: Handles clauses are not supported in C#
grdWireNo_DoubleClick(object sender, System.EventArgs e)
    {


      //FORMCLOSEEX2 = False
      //Me.Close()
      //'    strEcn = FRM.viewWiresView.GetRowCellValue(FRM.viewWiresView.GetSelectedRows(0), "bacWireNo")
      //    DrwNo = FRM.viewWiresView.GetRowCellValue(FRM.viewWiresView.GetSelectedRows(0), "bacRefdes1")
      //    TypeVer = FRM.viewWiresView.GetRowCellValue(FRM.viewWiresView.GetSelectedRows(0), "bacAction")
      //    RefDes = FRM.viewWiresView.GetRowCellValue(FRM.viewWiresView.GetSelectedRows(0), "bacRefDes2")
      //    If RefDes = "" Or RefDes = "-" Then



      //        Dim DS As New DataSet
      //        Dim DC As New clsData
      //        Dim SQL As String
      //        ACTION = TypeVer

      //        wireno1 = strEcn
      //        Dim REFID As Integer
      //        If ACTION Like "*ADD*" Then
      //            ACTION = "ADD"

      //            DS = DC.getData("SELECT * FROM  PTP WHERE WIRE_END_REF <> '" & DrwNo & "' AND WIRE_NUMBER = '" & strEcn & "' AND PART_NUMBER = '" & NewHarnessPTP & "'", ni)
      //            end1 = DS.Tables(0).Rows(0)("WIRE_END_REF")
      //            Pin = DS.Tables(0).Rows(0)("WIRE_END_PIN")
      //            Term = DS.Tables(0).Rows(0)("WIRE_END_PN")
      //            length1 = DS.Tables(0).Rows(0)("WIRE_LEN_MEAS")
      //            EndPoint = DS.Tables(0).Rows(0)("WIRE_END_CD")

      //            shield = ""



      //            DS = DC.getData("SELECT REFDESID  FROM TBLREFDES WHERE REFDES = '" & end1 & "' AND RefPlanId = '" & PlanNumber & "'", ni)
      //            If DS.Tables(0).Rows.Count = 0 Then

      //                DC.ExecuteSQL("INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW) VALUES ('" & end1 & "','',2,'" & HARNESSID & "','" & PlanNumber & "','Rework wires at " & end1 & " as follows and per 16PR145','')")
      //                'Get RefDesId
      //                SQL = ("SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '" & end1 & "' AND REFPLANID ='" & PlanNumber & "'")
      //                DS = DC.getData(SQL, ni)
      //                REFID = DS.Tables(0).Rows(0)("REFDESID")


      //            Else
      //                REFID = DS.Tables(0).Rows(0)("REFDESID")

      //            End If



      //            SQL = (String.Format("UPDATE tblBackShopWires SET bacRefDes2 = '{0}',bacPin2 ='{1}',bacTerm2 ='{2}' where (bacWireNo = '{3}' and bacPlId = '{4}' and bacAction ='{5}')", end1, Pin, Term, wireno1, PlanNumber, ACTION))
      //            DC.ExecuteSQL(SQL)
      //            SQL = "INSERT INTO tblWires "
      //            SQL = SQL & "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES "
      //            SQL = SQL & "('" & ACTION & "','" & strEcn & "'," & REFID & ",'" & Pin & "','" & length1 & "','" & Term & "','" & strEcn & "','" & end1 & "','','" & PlanNumber & "','" & EndPoint & "')"
      //            DC.ExecuteSQL(SQL)
      //            SQL = "INSERT INTO tblWiresAdd "
      //            SQL = SQL & "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES "
      //            SQL = SQL & "('" & ACTION & "','" & strEcn & "'," & REFID & ",'" & Pin & "','" & length1 & "','" & Term & "','" & strEcn & "','" & end1 & "','','" & PlanNumber & "','" & EndPoint & "')"
      //            DC.ExecuteSQL(SQL)

      //        ElseIf ACTION Like "*REM*" Then
      //            DS = DC.getData("SELECT * FROM  PTP WHERE WIRE_END_REF <> '" & DrwNo & "' AND WIRE_NUMBER = '" & strEcn & "' AND PART_NUMBER = '" & OldHarnessPTP & "'", ni)
      //            end1 = DS.Tables(0).Rows(0)("WIRE_END_REF")
      //            Pin = DS.Tables(0).Rows(0)("WIRE_END_PIN")
      //            Term = DS.Tables(0).Rows(0)("WIRE_END_PN")
      //            length1 = DS.Tables(0).Rows(0)("WIRE_LEN_MEAS")
      //            EndPoint = DS.Tables(0).Rows(0)("WIRE_END_CD")
      //            shield = ""


      //            ACTION = "REMOVE"
      //            DS = DC.getData("SELECT REFDESID  FROM TBLREFDES WHERE REFDES = '" & end1 & "' AND RefPlanId = '" & PlanNumber & "'", ni)
      //            If DS.Tables(0).Rows.Count = 0 Then

      //                DC.ExecuteSQL("INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW) VALUES ('" & end1 & "','',2,'" & HARNESSID & "','" & PlanNumber & "','Rework wires at " & end1 & " as follows and per 16PR145','')")
      //                'Get RefDesId
      //                SQL = ("SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '" & end1 & "' AND REFPLANID ='" & PlanNumber & "'")
      //                DS = DC.getData(SQL, ni)
      //                REFID = DS.Tables(0).Rows(0)("REFDESID")


      //            Else
      //                REFID = DS.Tables(0).Rows(0)("REFDESID")

      //            End If

      //            SQL = (String.Format("UPDATE tblBackShopWires SET bacRefDes2 = '{0}',bacPin2 ='{1}',bacTerm2 ='{2}' where (bacWireNo = '{3}' and bacPlId = '{4}' and bacAction ='{5}')", end1, Pin, Term, wireno1, PlanNumber, ACTION))
      //            DC.ExecuteSQL(SQL)
      //            SQL = "INSERT INTO tblWires "
      //            SQL = SQL & "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES "
      //            SQL = SQL & "('" & ACTION & "','" & strEcn & "'," & REFID & ",'" & Pin & "','" & length1 & "','" & Term & "','" & strEcn & "','" & end1 & "','','" & PlanNumber & "','" & EndPoint & "')"
      //            DC.ExecuteSQL(SQL)
      //            SQL = "INSERT INTO tblWiresREMOVE "
      //            SQL = SQL & "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES "
      //            SQL = SQL & "('" & ACTION & "','" & strEcn & "'," & REFID & ",'" & Pin & "','" & length1 & "','" & Term & "','" & strEcn & "','" & end1 & "','','" & PlanNumber & "','" & EndPoint & "')"
      //            DC.ExecuteSQL(SQL)

      //        End If


      //        FRM.daWiresView.Fill(FRM.dsElectrical, "tblBackShopWires")


      //        'viewBackShopWires.SetRowCellValue(viewBackShopWires.FocusedRowHandle, "bacRefDes2", "Filled")

      //    End If
    }

    private void  // ERROR: Handles clauses are not supported in C#
frmWireNo_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
    {
      // FormCloseex = FORMCLOSEEX2

    }

    private void  // ERROR: Handles clauses are not supported in C#
grdWireNo_Load(object sender, System.EventArgs e)
    {
        PLANNUM = Module1.newModule.plnumber;
    }

    private void  // ERROR: Handles clauses are not supported in C#
frmCardHarness_Load(object sender, System.EventArgs e)
    {
      Module1.newModule.fillOldHarness(grdWireNo, Module1.newModule.oldharn, Module1.newModule.newharn);//JMR

    }

    private void  // ERROR: Handles clauses are not supported in C#
txtSwire_Validated(object sender, System.EventArgs e)
    {
      try {
        txtSwire.BackColor = Color.White;
      } catch (Exception ex) {

      }
      if (txtSwire.Text.Length == 2) {
        txtSwire.Text = "0" + txtSwire.Text;
      }
      DataSet dsas = new DataSet();
      clsData dc = new clsData();
      string TR = "";
      string tr2 = "";
      if (ComboBoxEdit1.Text == "REMOVE") {
        tr2 = Module1.newModule.oldharn;
      } else if (ComboBoxEdit1.Text == "Revise From") {
          tr2 = Module1.newModule.oldharn;
      } else {
          tr2 = Module1.newModule.newharn;
      }
      TR = Module1.newModule.newharn.Substring(4, Module1.newModule.newharn.Length - Module1.newModule.newharn.IndexOf("-") + 2);
      txtSwire.Text = txtSwire.Text.Replace(TR, "");
      string fd = "";
      if (txtSwire.Text.StartsWith(TR)) {
        dsas = dc.getData("SELECT * FROM PTP2 WHERE part_number ='" + tr2 + "' and  WIRE_NUMBER LIKE '" + txtSwire.Text + "%'");


      } else {
        dsas = dc.getData("SELECT * FROM PTP2 WHERE part_number ='" + tr2 + "' and  WIRE_NUMBER LIKE '" + TR + txtSwire.Text + "%'");
        if (dsas.Tables[0].Rows.Count == 0) {
          dsas = dc.getData("SELECT * FROM PTP2 WHERE part_number ='" + tr2 + "' and  WIRE_NUMBER LIKE '" + txtSwire.Text + "%'");

        }
        if (dsas.Tables[0].Rows.Count == 0) {
          dsas = dc.getData("SELECT * FROM PTP2 WHERE part_number ='" + Module1.newModule.oldharn + "' and  WIRE_NUMBER LIKE '" + txtSwire.Text + "%'");

        }
      }
      try {
        /*
        txtSrefd.Text = dsas.Tables[0].Rows[0].Item("WIRE_END_REF");        
        txtSwire.Text = dsas.Tables[0].Rows[0].Item("WIRE_NUMBER");
        txtSpin.Text = dsas.Tables[0].Rows[0].Item("WIRE_END_PIN");
        txtSterm.Text = dsas.Tables[0].Rows[0].Item("WIRE_END_PN");
        txtSlength.Text = dsas.Tables[0].Rows[0].Item("WIRE_LEN_MEAS");
        txtSend.Text = dsas.Tables[0].Rows[0].Item("WIRE_END_CD");
        srefd2.Text = dsas.Tables[0].Rows[1].Item("WIRE_END_REF");
        // swire2.Text = dsas.Tables(0).Rows(1).Item("WIRE_NUMBER")
        spin2.Text = dsas.Tables[0].Rows[1].Item("WIRE_END_PIN");
        sterm2.Text = dsas.Tables[0].Rows[1].Item("WIRE_END_PN");
        slength2.Text = dsas.Tables[0].Rows[1].Item("WIRE_LEN_MEAS");
        send2.Text = dsas.Tables[0].Rows[1].Item("WIRE_END_CD");
        */

          //JMR -- Replaced above block with this block. Item is already implied. Source-http://www.tek-tips.com/viewthread.cfm?qid=589273
        txtSrefd.Text = Conversions.ToString(dsas.Tables[0].Rows[0]["WIRE_END_REF"]);
        txtSwire.Text = Conversions.ToString(dsas.Tables[0].Rows[0]["WIRE_NUMBER"]);
        txtSpin.Text = Conversions.ToString(dsas.Tables[0].Rows[0]["WIRE_END_PIN"]);
        txtSterm.Text = Conversions.ToString(dsas.Tables[0].Rows[0]["WIRE_END_PN"]);
        txtSlength.Text = Conversions.ToString(dsas.Tables[0].Rows[0]["WIRE_LEN_MEAS"]);
        txtSend.Text = Conversions.ToString(dsas.Tables[0].Rows[0]["WIRE_END_CD"]);
        srefd2.Text = Conversions.ToString(dsas.Tables[0].Rows[1]["WIRE_END_REF"]);
        //swire2.Text = Conversions.ToString(dsas.Tables(0).Rows(1)["WIRE_NUMBER"]);
        spin2.Text = Conversions.ToString(dsas.Tables[0].Rows[1]["WIRE_END_PIN"]);
        sterm2.Text = Conversions.ToString(dsas.Tables[0].Rows[1]["WIRE_END_PN"]);
        slength2.Text = Conversions.ToString(dsas.Tables[0].Rows[1]["WIRE_LEN_MEAS"]);
        send2.Text = Conversions.ToString(dsas.Tables[0].Rows[1]["WIRE_END_CD"]);



      } catch (Exception ex) {
        txtSpin.Text = "";
        txtSlength.Text = "";
        txtSend.Text = "";
        txtSterm.Text = "";
        txtSrefd.Text = "";
        spin2.Text = "";
        send2.Text = "";
        srefd2.Text = "";
        spin2.Text = "";
        slength2.Text = "";
        sterm2.Text = "";

      }
      // 
    }

    private void  // ERROR: Handles clauses are not supported in C#
viewWireNo_Click(object sender, System.EventArgs e)
    {
        txtSwire.Text = Conversions.ToString(viewWireNo.GetRowCellValue(Conversions.ToInteger(viewWireNo.GetSelectedRows()), "WIRE_NUMBER"));//JMR -- Converted etc.GetSelectedRows() to int and got rid of the 0 inside it, then converted the whole thing to string.
      txtSwire_Validated(txtSwire.Text, e);

    }

    private void  // ERROR: Handles clauses are not supported in C#
Button1_Click(object sender, System.EventArgs e)
    {
        string SQL = "";
      clsData DC = new clsData();
      clsData DATA = new clsData();
      string STR2 = "";

      if (ComboBoxEdit1.Text == "FROM TRANSFORMER") {
        STR2 = string.Concat(new string[] {
          "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
          srefd2.Text,
          "' AND REFPLANID ='",
          PLANNUM,
          "'"
        });
        DataSet set2 = DATA.getData(STR2);
        if ((set2.Tables[0].Rows.Count == 0)) {
          DATA.ExecuteSQL(string.Concat(new string[] {
            "INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW,BASEREF) VALUES ('",
            srefd2.Text,
            "','',2,'",
            Module1.newModule.HARNESSID,//JMR
            "','",
            PLANNUM,
            "','Rework wires at WIRE TIE ",
            srefd2.Text,
            " as follows and per 16PR145','','",
            srefd2.Text,
            "')"
          }));
          STR2 = string.Concat(new string[] {
            "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
            srefd2.Text,
            "' AND REFPLANID ='",
            PLANNUM,
            "'"
          });
          Module1.newModule.RefDesId = Conversions.ToInteger(DATA.getData(STR2).Tables[0].Rows[0]["REFDESID"]);//JMR -- Converted to Int
        } else {
            Module1.newModule.RefDesId = Conversions.ToInteger(set2.Tables[0].Rows[0]["REFDESID"]);//JMR -- Converted to Int
        }

        SQL = "INSERT INTO tblWires ";
        SQL = SQL + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ";
        SQL = SQL + "('" + ComboBoxEdit1.Text + "','" + txtSwire.Text + "'," + Module1.newModule.RefDesId + ",'" + spin2.Text + "','" + txtSlength.Text + "','" + sterm2.Text + "','" + txtSwire.Text + "','" + srefd2.Text + "','" + txtSrefd.Text + "','" + PLANNUM + "','" + send2.Text + "')";
        DC.ExecuteSQL(SQL);

      } else if (ComboBoxEdit1.Text == "REFERENCE") {
        if (srefd2.Text.Contains("WT")) {
          STR2 = string.Concat(new string[] {
            "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
            srefd2.Text,
            "' AND REFPLANID ='",
            PLANNUM,
            "'"
          });
          DataSet set2 = DATA.getData(STR2);
          if ((set2.Tables[0].Rows.Count == 0)) {
            DATA.ExecuteSQL(string.Concat(new string[] {
              "INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW,BASEREF) VALUES ('",
              srefd2.Text,
              "','',2,'",
              Module1.newModule.HARNESSID,
              "','",
              PLANNUM,
              "','Rework wires at WIRE TIE ",
              srefd2.Text,
              " as follows and per 16PR145','','",
              srefd2.Text,
              "')"
            }));
            STR2 = string.Concat(new string[] {
              "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
              srefd2.Text,
              "' AND REFPLANID ='",
              PLANNUM,
              "'"
            });
            Module1.newModule.RefDesId = Conversions.ToInteger(DATA.getData(STR2).Tables[0].Rows[0]["REFDESID"]);//JMR -- Converted to Int
          } else {
              Module1.newModule.RefDesId = Conversions.ToInteger(set2.Tables[0].Rows[0]["REFDESID"]);//JMR -- Converted to Int
          }
          SQL = "INSERT INTO tblWires ";
          SQL = SQL + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ";
          SQL = SQL + "('" + ComboBoxEdit1.Text + "','" + txtSwire.Text + "'," + Module1.newModule.RefDesId + ",'" + txtSpin.Text + "','" + txtSlength.Text + "','" + sterm2.Text + "','" + txtSwire.Text + "','" + srefd2.Text + "','" + txtSrefd.Text + "','" + PLANNUM + "','" + send2.Text + "')";
          DC.ExecuteSQL(SQL);
        } else {
          STR2 = string.Concat(new string[] {
            "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
            txtSrefd.Text,
            "' AND REFPLANID ='",
            PLANNUM,
            "'"
          });
          DataSet set2 = DATA.getData(STR2);
          if ((set2.Tables[0].Rows.Count == 0)) {
            DATA.ExecuteSQL(string.Concat(new string[] {
              "INSERT INTO TBLREFDES (REFDES,REPORTNOTE,OPN,HARNESS,REFPLANID,REFWT,REFPREVIEW,BASEREF) VALUES ('",
              txtSrefd.Text,
              "','',2,'",
              Module1.newModule.HARNESSID,
              "','",
              PLANNUM,
              "','Rework wires at WIRE TIE ",
              txtSrefd.Text,
              " as follows and per 16PR145','','",
              txtSrefd.Text,
              "')"
            }));
            STR2 = string.Concat(new string[] {
              "SELECT REFDESID AS REFDESID FROM TBLREFDES WHERE REFDES = '",
              txtSrefd.Text,
              "' AND REFPLANID ='",
              PLANNUM,
              "'"
            });
            Module1.newModule.RefDesId = Conversions.ToInteger(DATA.getData(STR2).Tables[0].Rows[0]["REFDESID"]);//JMR -- Converted to Int
          } else {
              Module1.newModule.RefDesId = Conversions.ToInteger(set2.Tables[0].Rows[0]["REFDESID"]);//JMR -- Converted to Int
          }
          SQL = "INSERT INTO tblWires ";
          SQL = SQL + "(WIREACTid,WIRENO,wREFDESid,PIN,LENGTH,TERM,SWIRENO,SREFDES,SHIELD,WIRESPLID,ENDPOINT) VALUES ";
          SQL = SQL + "('" + ComboBoxEdit1.Text + "','" + txtSwire.Text + "'," + Module1.newModule.RefDesId + ",'" + spin2.Text + "','" + txtSlength.Text + "','" + txtSterm.Text + "','" + txtSwire.Text + "','" + txtSrefd.Text + "','" + srefd2.Text + "','" + PLANNUM + "','" + txtSend.Text + "')";
          DC.ExecuteSQL(SQL);
        }

      }
      MessageBox.Show("Wire added", "Add Wire");
    }

      public frmCardHarness()
    {
        InitializeComponent(); 
    }
  }
}

